


import {
  get,
  post,
  put,
} from "./base_service"


/**
 * 佳宝首页相关接口
 *
 * allen  2023-12-19
 */

/**
 * 
 * 获取地址列表
 */
const queryAddressList = () => {
  return new Promise((resolve, reject) => {
    get("/api/front/address/list?page=1&limit=50").then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
 * 
 * 设置默认地址
 */
const setDefaultAddress = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/address/default/set", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
* 
* 删除一个地址
*/
const deleteAddress = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/address/del", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}
/**
* 
* 编辑或者添加一个地址
*/
const editAddress = (data) => {
  return new Promise((resolve, reject) => {
    post("/api/front/address/edit", data).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}

/**
* 
* 根据id查询地址详情
*/
const queryAddressDetail = (addressId) => {
  return new Promise((resolve, reject) => {
    get("/api/front/address/detail/" + addressId).then((data) => {
      if (data.code == 200) {
        resolve(data)
      } else {
        reject(data.message)
      }
    }).catch((e) => {
      reject(e.message)
    })
  })
}




module.exports = {
  queryAddressList,
  setDefaultAddress,
  deleteAddress,
  editAddress,
  queryAddressDetail
}

